﻿#region File Header
/***********************************************************************
 * This code is released into the public domain under WTFPL. Simply put:
 * You may use this code in whatever way you want, commercial or
 * personal.
 * 
 * Check exceltocsv.codeplex.com for updates to the original code.
************************************************************************
Author: Donald Beals
Date: September 3rd, 2013
Description: Stores symbols that are useful to the main program, but
 * cannot be categorized.
****************************** Change Log ******************************
09.03.13 - Created initial file. (dbeals)
***********************************************************************/
#endregion

#region Using Statements
using System.Collections.Generic;
using Microsoft.Office.Interop.Excel;
#endregion

namespace ExcelToCSV
{
	/// <summary>
	/// 
	/// </summary>
	public static class Helper
	{
		public static Dictionary<string, string> GetFlags(string[] arguments)
		{
			var output = new Dictionary<string, string>();
			foreach(var argument in arguments)
			{
				if(argument[0] == '/')
				{
					var parts = argument.Split('=');
					if(parts.Length == 1)
						output.Add(parts[0].Substring(1).ToLower(), "true");
					else
						output.Add(parts[0].Substring(1).ToLower(), parts[1]);
				}
			}
			return output;
		}

		public static int CalculateProgress(int currentProgressIndex, int columnCount, int rowCount)
		{
			return CalculateProgress(currentProgressIndex, columnCount * rowCount);
		}

		public static int CalculateProgress(int currentProgressIndex, int totalSize)
		{
			return (int)(((float)currentProgressIndex / (float)totalSize) * 100);
		}

		public static bool IsWorksheetRangeEmpty(Range range)
		{
			if(range.Count == 1)
				return range[1, 1].Value2 == null;
			return false;
		}
	}
}
